<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const props = defineProps({
  dailyReports: {
    type: Array,
    required: true,
    default: () => []
  }
})

const emit = defineEmits(['edit', 'delete'])

const handleEdit = (report) => {
  emit('edit', report)
}

const handleDelete = (report) => {
  emit('delete', report)
}

const getCategoryColor = (category) => {
  const colors = {
    'Hardware': '#e6f7ff',
    'Software': '#f6ffed',
    'EFM': '#fff7e6',
    'VTM': '#f9f0ff'
  }
  return colors[category] || '#f5f5f5'
}

const getModuleColor = (module) => {
  const colors = {
    'EFM': '#1890ff',
    'VTM': '#722ed1',
    'Loadlock': '#fa8c16'
  }
  return colors[module] || '#595959'

const isAdmin = localStorage.getItem('isAdmin')
const userId = localStorage.getItem('userId')
}
</script>

<template>
  <div class="daily-list">
    <div v-for="report in props.dailyReports" 
         :key="report.id" 
         class="daily-item"
         :style="{ backgroundColor: getCategoryColor(report.category) }">
      <div class="daily-header">
        <div class="category-tags">
          <span class="category-tag">{{ report.category }}</span>
          <span class="module-tag" :style="{ backgroundColor: getModuleColor(report.module) }">{{ report.module }}</span>
          <span class="component-tag">{{ report.component }}</span>
        </div>
        <div class="actions" v-if="isAdmin || userId == report.userId">
          <button @click="handleEdit(report)" class="action-btn">修改</button>
          <button @click="handleDelete(report)" class="action-btn">删除</button>
        </div>
      </div>
      
      <div class="daily-title">{{ report.title }}</div>
      
      <div class="daily-info">
        <div class="info-row">
          <span class="info-label">发生时间：</span>
          <span class="info-value">{{ report.occurTime }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">记录时间：</span>
          <span class="info-value">{{ report.recordTime }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">更新时间：</span>
          <span class="info-value">{{ report.updateTime }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">截止日期：</span>
          <span class="info-value">{{ report.deadline }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">责任所属：</span>
          <span class="info-value">{{ report.responsibility }}</span>
        </div>
        <div class="info-row">
          <span class="info-label">记录人员：</span>
          <span class="info-value">{{ report.recorder }}</span>
        </div>
      </div>
      
      <div class="daily-content">
        <div class="content-section">
          <div class="section-label">进展：</div>
          <div class="section-text">{{ report.progress }}</div>
        </div>
        <div class="content-section">
          <div class="section-label">改善：</div>
          <div class="section-text">{{ report.improvement }}</div>
        </div>
        <div class="content-section">
          <div class="section-label">结果：</div>
          <div class="section-text">{{ report.result }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.daily-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.daily-item {
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.daily-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.category-tags {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.category-tag,
.module-tag,
.component-tag {
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.category-tag {
  background-color: #1890ff;
  color: white;
}

.module-tag {
  color: white;
}

.component-tag {
  background-color: #f5f5f5;
  color: #595959;
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.action-btn {
  padding: 0.25rem 0.75rem;
  border: none;
  border-radius: 4px;
  background-color: white;
  color: #595959;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background-color: #f5f5f5;
}

.daily-title {
  font-size: 1.2rem;
  font-weight: bold;
  color: #262626;
  margin-bottom: 1rem;
}

.daily-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-label {
  color: #8c8c8c;
  font-size: 0.9rem;
}

.info-value {
  color: #262626;
  font-size: 0.9rem;
}

.daily-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.content-section {
  background-color: rgba(255, 255, 255, 0.8);
  padding: 1rem;
  border-radius: 4px;
}

.section-label {
  color: #595959;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.section-text {
  color: #262626;
  line-height: 1.5;
  white-space: pre-wrap;
}
</style>